#ifndef TC_TRACE_HH
#define TC_TRACE_HH

/** \file Trace.hh 
 * Declarations for Trace class
 *
 * (c) Copyright  Semih Cemiloglu
 * All rights reserved, see COPYRIGHT file for details.
 *
 * $Id: Log.hh,v 1.3 2008/10/09 04:51:41 bdssadm Exp $
 *
 *
 */

// Project headers
#include "Global.hh"
#include "CodeContext.hh"

namespace TC {

class Trace {
  
  // FRIENDS
  friend void TraceEnter(const Trace* t);
  friend void TraceExit(const Trace* t);
  
 public:
  // CREATORS
  Trace(const CodeContext* ctx) : m_ctx(ctx)
  { TraceEnter(this); }
  //! Destroy Trace object
  ~Trace()
  { TraceExit(this); }

   // MEMBERS
  //! Id string this trace object (usually set as TC_FUNCTION)
  const CodeContext* m_ctx;

  // STATIC MEMBERS
  //! Enable global tracking of traces
  static TC_VOLATILE bool s_GlobalEnable;
  //! Enable thread-specific tracking of traces
  static TC_THREAD_LOCAL bool s_ThreadEnable;

  private:
  // NOT ALLOWED
  Trace();
  Trace(const Trace&);
  void operator=(const Trace&);

};  
    

} // end namespace


#ifdef TC_NOTRACE
# define TC_TRACE        ((void)0)
# define TC_TRACE_ID(Id) ((void)0)
#else
# define TC_TRACE  \
  static ::TC::CodeContext __context(__FILE__, __LINE__, TC_FUNCTION); \
  ::TC::Trace __trace(&__context)
# define TC_TRACE_ID(Id)  \
  static ::TC::CodeContext __context(__FILE__, __LINE__, Id); \
  ::TC::Trace __trace_id(&__context)
#endif

#endif /* Include guard */
